package com.example.test_20210601_Fruits;

public class FruitsFactoryImpl implements FruitsFactory {
    @Override
    public Fruits createFruits(Class c) {

        Fruits fruits = null;
        try {
            fruits = (Fruits)Class.forName(c.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return fruits;
    }

    public static void main(String[] args) {

        FruitsFactoryImpl fruitsFactory = new FruitsFactoryImpl();
        fruitsFactory.createFruits(Fruits.AppleImpl.class).show();
        fruitsFactory.createFruits(Fruits.PearImpl.class).show();
    }
}
